import requests


def get_auth_url():
    weibo_auth_url = 'https://api.weibo.com/oauth2/authorize'
    client_id = '715947986'
    redirect_uri = 'http://45.40.193.155:8000/complete/weibo/'
    auth_url = weibo_auth_url + '?client_id={client_id}&redirect_uri={redirect_uri}'.format(client_id=client_id,
                                                                                            redirect_uri=redirect_uri)
    print(auth_url)


def get_access_token(code='a4c2661337a2d453c39f9783b934103c'):
    access_token_url = 'https://api.weibo.com/oauth2/access_token'
    return_dict = requests.post(access_token_url, data={
        'client_id': '715947986',
        'client_secret': 'c3f35a93dc687b89b29c8a024e77070d',
        'grant_type': 'authorization_code',
        'code': code,
        'redirect_uri': 'http://45.40.193.155:8000/complete/weibo/'
    })
    pass


def get_user_info(acceess_token="", uid=''):
    user_url = 'https://api.weibo.com/2/users/show.json?access_token={token}&uid={uid}'.format(token=acceess_token,
                                                                                               uid=uid)
    print(user_url)
    # response = requests.get(user_url)
    pass


if __name__ == "__main__":
    # get_auth_url()
    get_access_token(code='a4c2661337a2d453c39f9783b934103c')
    get_user_info(acceess_token='2.003WAHcC0KmC9m0129c40079QDhAnD', uid='2395436734')
